package com.tong.hao.ac.service.annotation.condition.config;

import com.tong.hao.ac.service.annotation.condition.LinuxCondition;
import com.tong.hao.ac.service.annotation.condition.WinCondition;
import com.tong.hao.ac.service.annotation.condition.model.ConditionModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName ConditionBeanConf
 * @Author 友野浩二
 * @Version 1.0
 */
@Configuration
public class ConditionBeanConf {

    // @Conditional是Spring4新提供的注解，它的作用是按照一定的条件进行判断，满足条件给容器注册bean。
    @Conditional({WinCondition.class})
    @Bean(name = "Tong")
    public ConditionModel model1() {
        return ConditionModel.builder().name("Zhang Tong").age(25).build();
    }

    @Conditional(LinuxCondition.class)
    @Bean(name = "Hao")
    public ConditionModel model2() {
        return ConditionModel.builder().name("Shi Hao").age(25).build();
    }

}
